package com.diyizu.service.impl;

import com.diyizu.dao.IStudentInfoDao;
import com.diyizu.dao.impl.StudentInfoDaoImpl;
import com.diyizu.domain.Student;
import com.diyizu.factory.Factory;
import com.diyizu.service.IStudentInfoService;

import java.util.ArrayList;

public class StudentInfoServiceImpl implements IStudentInfoService {
    IStudentInfoDao studentInfoDao = Factory.getStudentInfoDao();
    @Override
    public void addStudent(Student student) {
        studentInfoDao.addStudent(student);
    }

    @Override
    public void deleteStudent(String sid) {
        studentInfoDao.deleteStudent(sid);
    }

    @Override
    public void updateStudent(String sid, Student stu) {
        studentInfoDao.updateStudent(sid,stu);
    }

    @Override
    public ArrayList<Student> findAllStudents() {

        return studentInfoDao.findAllStudents();
    }

    @Override
    public Student getStudentToPhone(String phone) {
        return studentInfoDao.getSid(phone);
    }

    @Override
    public Student getStudentToName(String name) {
        return studentInfoDao.getId(name);
    }

    @Override
    public boolean isExists(String sid) {
        ArrayList<Student> list = studentInfoDao.findAllStudents();
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getSid().equals(sid)){
                return true;
            }
        }
        return false;
    }
}
